<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
// +----------------------------------------------------------------------

namespace Admin\Controller;


/**
 * 前台首页控制器
 * 主要获取首页聚合数据
 */
class BoothguanliController extends AdminController {
    
	//展位管理
	public function booth_guanli(){
        $map = array();
        $map  = array('active' => 1);
		//模糊匹配
        $name=I('name');
		if(is_numeric($name)){
			$map['id|boothname']=array(intval($name),array('like','%'.$name.'%'),'_multi'=>true);//'_multi'=>true表示多条件匹配
		}else{
		    $map['boothname']=array('like','%'.(string)$name.'%');
		}
		
		$lists = $this->lists('Booth_info',$map,'id ');
    	$this->assign('boothguanli',$lists);
	 
	    $this->display();
	}
	//展位编辑
	public function edit($id=0){
	    if(IS_POST){
            $booth_info = D('Booth_info');
            $data = $booth_info->create();
            //var_dump($data);exit;
            if($data){
                if($booth_info->save()!== false){
                    
                    $this->success('更新成功',U('Boothguanli/booth_guanli'));
                } else {
                    $this->error('更新失败');
                }
            } else {
                $this->error($booth_info->getError());
            }
		
		 }else {
            $info = array();
            /* 获取数据 */
            $info = M('Booth_info')->find($id);
            $Booth = M('Booth_info')->field(true)->select();
            $Booth = D('Common/Tree')->toFormatTree($Booth);
            $this->assign('info', $info);
            $this->display('booth_bianji');
       }
	}

	
	//删除
	 public function del(){
       $id = array_unique((array)I('id',0));

        if ( empty($id) ) {
            $this->error('请选择要操作的数据!');
        }

        $map = array('id' => array('in', $id) );
        if(M('Booth_info')->where($map)->delete()){
           
            $this->success('删除成功');
        } else {
            $this->error('删除失败！');
        }
    }

	//屏蔽，开启，删除

	public function changestatus($method=null){
		$id=array_unique((array)I('id',0));
		$id=is_array($id) ? implode(',',$id) : $id;
		//var_dump($id);exit;
		if(empty($id)){
			$this->error('请选择要操作的数据');
		}
		$where['id']=array('in',$id);
		switch(strtolower($method)){
			case 'forbidbooth':
				$this->forbid('Booth_info',$where);
				break;
            case 'resumebooth':
	            $this->resume('Booth_info',$where);
	            break;
	        case 'deletebooth':
		        $this->delete('Booth_info',$where);
		        break;
	        default:
		        $this->error(参数非法);
		}
	}



}




?>